package Storage;

import java.util.ArrayList;
import Object.DSHistory;
import Object.DSQuery;
import Task.DSTask;

//@author A0103535R
/************************************ Abstract Class DSHistoryStore ***************************/
public class DSHistoryStore {
	
        private static DSHistoryStore _historyStore; 
        private ArrayList<DSHistory> _historyList;
        
    	/**
    	 * This is the constructor of DSHistoryStore
    	 */
        private DSHistoryStore(){
                this._historyList = new ArrayList<DSHistory>();
        }
        
    	/**
    	 * This function is used to get the instance singleton of DSHistoryStore
    	 * 
    	 * @return the singleton instance of DSHistoryStore
    	 */
        public static DSHistoryStore getInstance(){
                if(_historyStore == null){
                        _historyStore = new DSHistoryStore();
                }
                return _historyStore;
        }
        
    	/**
    	 * This function is used to add new task related history in DSHistoryStore
    	 * 
    	 * @param type 
    	 * 			history type of new history to add
    	 * @param task
    	 * 			task to record in this history
    	 */
        public void addHistory(int type, DSTask task){
                this._historyList.add(new DSHistory(type, task));
        }
        
    	/**
    	 * This function is used to add new search related history in DSHistoryStore
    	 * 
    	 * @param type 
    	 * 			history type of new history to add
    	 * @param query
    	 * 			query to record in this history
    	 */
        public void addHistory(int type, DSQuery query){
                this._historyList.add(new DSHistory(type, query));
        }
        
    	/**
    	 * This function is used to get the last history added in store.
    	 * 
    	 * @return the last history added in store
    	 */
        public DSHistory getLastHistory(){
                if(this._historyList.size()>0){
                        return this._historyList.remove(_historyList.size()-1);
                }  
                return null;
        }
}